<?php
/**
 * array to xml
 * 
 * 
 * @author fu 20120411
 *
 */
class array2xml {
	
	var $xml;
	
	public function getXml($array, $encoding='utf-8'){
		$this->xml='<?xml version="1.0" encoding="'.$encoding.'"?>';
		$this->xml.=$this->_array2xml($array);
		return $this->xml;
	}
	
	private function _array2xml($array){
		$xml='';
		foreach($array as $key=>$val)
		{
			is_numeric($key)&&$key="item id=\"$key\"";
			$xml.="<$key>";
			$xml.=is_array($val)?$this->_array2xml($val):$val;
			list($key,)=explode(' ',$key);
			$xml.="</$key>";
		}
		return $xml;
	}
}